<?php

/**
 * This is the model class for table "Livraison".
 *
 * The followings are the available columns in table 'Livraison':
 * @property integer $id
 * @property string $libelle
 * @property string $civilite
 * @property string $nom
 * @property string $prenom
 * @property string $adresse
 * @property string $codePostal
 * @property string $ville
 * @property string $pays
 * @property string $tel
 * @property integer $id_client
 *
 * The followings are the available model relations:
 * @property Commande[] $commandes
 * @property Client $client
 */
class Livraison extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Livraison the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'Livraison';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('libelle, civilite, nom, prenom, adresse, codePostal, ville, pays, tel, id_client', 'required'),
			array('civilite', 'length', 'max'=>4),
			array('codePostal', 'length', 'max'=>5, 'min'=>5),
			array('codePostal', 'numerical', 'integerOnly'=>true),
			array('nom, prenom, libelle', 'length', 'max'=>50),
			array('adresse', 'length', 'max'=>500),
			array('ville', 'length', 'max'=>100),
			array('tel', 'length', 'max'=>20),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, libelle, civilite, nom, prenom, adresse, codePostal, ville, pays, tel, id_client', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'commandes' => array(self::HAS_MANY, 'Commande', 'id_livraison'),
			'client' => array(self::BELONGS_TO, 'Client', 'id_client'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'libelle' => 'Libellé de l\'adresse',
			'civilite' => 'Civilité',
			'nom' => 'Nom',
			'prenom' => 'Prénom',
			'adresse' => 'Adresse',
			'codePostal' => 'Code Postal',
			'ville' => 'Ville',
			'pays' => 'Pays',
			'tel' => 'Téléphone',
			'id_client' => 'Id Client',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('libelle',$this->libelle,true);
		$criteria->compare('civilite',$this->civilite,true);
		$criteria->compare('nom',$this->nom,true);
		$criteria->compare('prenom',$this->prenom,true);
		$criteria->compare('adresse',$this->adresse,true);
		$criteria->compare('codePostal',$this->codePostal,true);
		$criteria->compare('ville',$this->ville,true);
		$criteria->compare('pays',$this->pays,true);
		$criteria->compare('tel',$this->tel,true);
		$criteria->compare('id_client',$this->id_client);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}